package com.future.common.security.service;

import com.future.common.api.content.CacheConstants;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;

/**
 * @ClassName : StatusClientDetailService
 * @Author : lby
 * @Date: 2021/5/6 21:48
 * @Description : client details service
 */
public class StatusClientDetailService extends JdbcClientDetailsService {
    public StatusClientDetailService(DataSource dataSource) {
        super(dataSource);
    }

    /**
     * 重写原生方法支持redis缓存
     *
     * @param clientId
     * @return
     * @throws
     */
    @Override
    @Cacheable(value = CacheConstants.GLOBALLY + CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
    public ClientDetails loadClientByClientId(String clientId) {
        return super.loadClientByClientId(clientId);
    }
}
